import { onMounted,onUnmounted } from "vue";

const useKeyPress = (key: string, callback: () => any) => {
  const trigger = (e: KeyboardEvent) => {
    if (e.key === key) {
      callback();
    }
  }

  onMounted(() => {
    document.addEventListener('keydown', trigger);
  })
  onUnmounted(() => {
    document.removeEventListener('keydown', trigger);
  })
}

export default useKeyPress;